package com.kinon.barber.tools;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class HttpTools {
	Context context;
	AsyncHttpClient client=new AsyncHttpClient();
	
	public HttpTools(Context context) {
		super();
		this.context = context;
	}
	/**登录*/
	public void login(String username, String password,String type,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("username", username);
		params.put("password", password);
		params.put("type", type);
		client.post(context, Url.loginUrl, params, backcall);
	}
	/**确认*/
	public void queren(String token, String orderid,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.querenUrl, params, backcall);
	}
	/**已完成*/
	public void yiwancheng(String token, String orderid,String state,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		params.put("state", state);
		client.post(context, Url.querenUrl, params, backcall);
	}
	/**订单列表*/
	public void order(String token, String page,String offset,String type,String recmode,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("page", page);
		params.put("offset", offset);
		params.put("type", type);
		params.put("recmode", recmode);
		client.post(context, Url.orderUrl, params, backcall);
	}
	/**订单详情*/
	public void detail(String token, String orderid,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.detailUrl, params, backcall);
	}
	
	/**打印订单*/
	public void printorder(String token, String orderid,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.printorderUrl, params, backcall);
	}
	
	/**无商品保存订单 */
	public void saveNewOrder(String token, String total,String type,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("total", total);
		params.put("type", type);
		client.post(context, Url.saveNewOrder, params, backcall);
	}
	
	/**结算 */
	public void otherPay(String token, String orderid,String no,String type,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		params.put("no", no);
		params.put("type", type);
		client.post(context, Url.otherPay, params, backcall);
	}
	/**订单列表 */
	public void getOrders(String token, String page,String offset,String type,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("page", page);
		params.put("offset", offset);
		params.put("type", type);
		client.post(context, Url.getOrders, params, backcall);
	}

	/**用户信息*/
	public void UserInfo(String token, JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		client.post(context, Url.userInfo, params, backcall);
	}
	/**退款 */
	public void refund(String token, String orderid,
			JsonHttpResponseHandler backcall) {
		RequestParams params = new RequestParams();
		params.put("token", token);
		params.put("orderid", orderid);
		client.post(context, Url.refund, params, backcall);
	}
}
